//
//  UserCenterApi.swift
//  MT
//
//  Created by M on 2019/12/21.
//  Copyright © 2019 张强. All rights reserved.
//

import Foundation

import RxSwift
import RxDataSources
import Moya
import Result

enum UserCenterApi {
    
    /// 登录
    case login(_ params: [String: Any])
    /// 注册
    case register(_ params: [String: Any])
    /// 信息修改
    case modify(_ requestParam: [String : Any])
    /// 微信验证
    case validation(_ requestParam: [String : Any])
    /// 更新信息
    case update(_ id: Int)
    /// 用户信息初始化
    case initialization(_ requestParam: [String : Any])
    /// 女性用户审核视频
    case femaleVideoValidation(_ requestParam: [String : Any])
    /// 等待人数
    case auditStatus
    /// 查询用户余额
    case queryMoney
    /// 好友 / 俱乐部申请通过通知后台
    case notify(_ requestParam: [String : Any])
    /// 查询用户可提现金额
    case queryWithdraw
    /// 提现申请
    case applyWithdraw(_ requestParam: [String : Any])
    /// 查询换钻石
    case queryTranslateDiamond
    /// 换钻石
    case translateDiamond(_ amount: Int)
    /// 用户注册
    case userRegister(parameter: [String : Any])
    /// 忘记密码
    case forgetPassword(parameter: [String : Any])
    /// 获取短信验证码
    case sendVerify(parameter: [String : Any])
    /// 短信验证码登录+注册
    case codeLogin(parameter: [String: Any])
    
    /// 搜索用户
    case search(_ parameters: [String : Any])
    
    ///兑换钻石
    case translateTicket
    
    ///重置密码
    case resetPwd(parameter: [String: Any])
    
    ///提现信息
    case withdrawSummary
    
}

extension UserCenterApi: MTTargetType {
    
    /// 请求头
    public var headers: [String : String]? {
        guard let accessToken = UserDefaults.MTUserCenter.token.storedString else { return nil }
        return ["Access-Token": accessToken]
    }
    
    /// 基路径
    public var baseURL: URL {
        return URL(string: AuthServerBaseUrl)!
    }
    
    /// 路径
    public var path: String {
        switch self {
        case .login:
            return "/login/login"
            
        case .register:
            return "/login/register-mail"
            
        case .modify:
            return "/user/modify"
            
        case .validation(_):
            return "/login/validation"
            
        case let .update(id):
            return "/user/update/\(id)"
            
        case .initialization:
            return "/user/initialization"
            
        case .femaleVideoValidation:
            return "/user/femal-vedio"
            
        case .auditStatus:
            return "/user/audit_status"
        
        case .queryMoney:
            return "/user/money"
            
        case .notify(_):
            return "/user/notify"
            
        case .queryWithdraw:
            return "/user/query-withdraw"
            
        case .applyWithdraw:
            return "/user/withdrawApply"
            
        case .queryTranslateDiamond:
            return "/user/query-translate-diamond"
            
        case .translateDiamond:
            return "/user/translate-diamond"
            
        case .userRegister(_):
            return "/login/register-mail"
        case .forgetPassword(_):
            return "/login/forget"
        case .sendVerify(_):
            return "/login/send-verify"
        case .codeLogin(_):
            return "/login/login-mobile"
        case .search(_):
            return "/user/search"
        case .translateTicket:
            return "/user/translate-ticket"
        case .resetPwd(_):
            return "/login/mdy-pwd"
        case .withdrawSummary:
            return "/withdraw/summary"
        }
    }
    
    /// 请求方法
    public var method: Moya.Method {
        switch self {
        default:        return .post
        }
    }
    
    /// 参数
    var params: [String: Any]? {
        switch self {
            
        case let .login(params), let .register(params):
            return params
            
        case let .modify(requestParam):
            return requestParam
            
            /// 微信登录验证
        case let .validation(requestParam):
            return requestParam
            
        case let .initialization(requestParam):
            return requestParam
            
        case let .femaleVideoValidation(requestParam):
            return requestParam
            
        case .update:
            return nil
            
        case let .notify(requestParam):
            return requestParam
            
        case let .applyWithdraw(requestParam):
            return requestParam
            
        case let .translateDiamond(amount):
            return ["ticketAmount": amount]
            
        case let .userRegister(parameter), let .forgetPassword(parameter), let .sendVerify(parameter), let .codeLogin(parameter):
            return parameter
        case let .search(parameters):
            return parameters
        case .translateTicket:
            return nil
        case let .resetPwd(parameter):
            return parameter
        case .withdrawSummary:
            return nil
        default:
            return nil
        }
    }
    
}
